﻿using System;
using ComputationalCore.Helper;

namespace BehaviorModel.Block.RandomGenerator
{
    /// <summary>
    /// Random generator with Erlang strategy.
    /// </summary>
    public class ErlangRandomGenerator : IRandomGenerator
    {
        public double Lambda { get; set; }
        public int Order { get; set; }

        public ErlangRandomGenerator()
        {
            Lambda = 1;
            Order = 1;
        }

        public ErlangRandomGenerator(double lambda, int order)
        {
            Lambda = lambda;
            Order = order;
        }

        #region Get Next

        public double GetNext(double prevTime)
        {
            return GetNext() + prevTime;
        }

        public double GetNext()
        {
            double next = 0;
            for (int i = 0; i < Order; i++)
            {
                next += -1/Lambda*Math.Log(RandomHelper.NextDouble());
            }
            next /= Order;

            return next;
        }

        #endregion
    }
}
